APM.MainFrameController = Ember.Controller.extend({

	hideLeft: false,

	init: function(){
		if(window.location.href.indexOf("hidden") != -1){
			$('body').addClass("cossembed");
			$.cookie("cossembed", true, '/');
		}else{
			$.cookie("cossembed", "", -1);
		}
	},

	requireWargingNum: function() {
		var ctrl = this;
		
		var registerTast = function() {
			ctrl.timeTicket = setTimeout(function() {
				ctrl.queryWargingNum().then(function() {
					registerTast();
				})
			}, 60000);
		};

		registerTast();
		this.queryWargingNum();
	},

	stopQueryWargingNum: function(){
		clearTimeout(this.timeTicket);
	},

	queryWargingNum : function() {
		var ctrl = this;

		return this.store.ajax("GET", "alarms/alarmsWorstNum")
		.then(function(response) {
			var wargingNum = parseInt(response["result"], 10);
			if(wargingNum>99){
				wargingNum = "99+";
			}
			ctrl.set('wargingNum', wargingNum);
		});
	},

	logo: './apps/main/img/logo.png?v='+Math.random(),

	actions: {
		logout: function() {
			var me = this;
			
			this.store.ajax("PUT", "authentication/logout").then(function(response) {
				$.cookie("token", null, '/');
				me.set("auth.user", null);
				window.location.href = BASE_SYSTEM_URL;
			});
		}
	}
	
});